from fastapi import FastAPI
from tortoise.contrib.fastapi import register_tortoise
import uvicorn
from fastapi.middleware.cors import CORSMiddleware

# from common.config.database_config import TORTOISE_ORM
from router import router

app = FastAPI()

# 加载数据库
from common.config.ReadConfig import TORTOISE_ORM
register_tortoise(
    app=app,
    config=TORTOISE_ORM 
)

# 加载路由
app.include_router(router=router)

# 加载中间件
from middleware import CheckToken, ProcessTime
app.middleware("http")(CheckToken.check_token)
app.middleware("http")(ProcessTime.process_time)
app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=['*'],
    allow_headers=['*']
)

if __name__ == '__main__':

    uvicorn.run(app='main:app', host='0.0.0.0', port=9000, reload=True)
